
class HtmlOutputer(object):
    def __init__(self):
        self.datas = []

    def collect_data(self, data):
        if data is None:
            return
        self.datas.append(data)

    def outout_html(self):
        fout = open('output1.html', 'w', encoding='utf-8')

        fout.write('<html>')
        fout.write('<head>')
        fout.write('<title>中文标题</title>')
        fout.write('<meta charset="UTF-8"></meta>')
        fout.write('</head>')
        fout.write('<body>')
        fout.write('<table border = 1 cellspacing=0>')
        for data in self.datas:
            fout.write('<tr>')
            fout.write('<td width=200px><a href="{}">爬取结果 {}</a></td>'.format(data['url'], data['url']))
            fout.write('<td width=200px>{}</td>'.format(data['title']))
            fout.write('<td width=600px>{}</td>' .format(data['summary']))
            fout.write('</tr>')
        fout.write('</table>')
        fout.write('</body>')
        fout.write('</html>')
        fout.close()
